home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / Apple Guide / Engineering / APISample / APISampleCW / Source / TApplication.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-01  |  5.1 KB  |  131 lines  |  [TEXT/MPS ]

  1. /*------------------------------------------------------------------------------
  2. #
  3. #    Apple Macintosh Developer Technical Support
  4. #
  5. #    MultiFinder-Aware Simple Application Framework
  6. #
  7. #    TApplication
  8. #
  9. #    TApplication.h    -    C++ source
  10. #
  11. #    Copyright © 1991 Apple Computer, Inc.
  12. #    All rights reserved.
  13. #
  14. #    Versions:    
  15. #            1.20                    10/91
  16. #            1.10                     07/89
  17. #            1.00                     04/89
  18. #
  19. #    Components:
  20. #            TApplicationCommon.h    July 9, 1989
  21. #            TApplication.h            July 9, 1989
  22. #            TApplication.cp            July 9, 1989
  23. #            TApplication.r            July 9, 1989
  24. #            TDocument.h                July 9, 1989
  25. #
  26. #    CPlusAppLib is a rudimentary application framework
  27. #    for C++. The applications CPlusShapesApp and CPlusTESample
  28. #    are built using CPlusAppLib.
  29. #
  30. ------------------------------------------------------------------------------*/
  31.  
  32. #ifndef TAPPLICATION_H
  33. #define TAPPLICATION_H
  34.  
  35. // Include necessary interface files
  36. #include <Types.h>
  37. #include <Desk.h>
  38. #include <Events.h>
  39. #include <OSUtils.h>
  40.  
  41. // we need definitions of our base classes
  42. // Includes are relative to the including file, not the included file.
  43. // If we are building our main, then the TApplication and TDocument
  44. // header folders are enclosed in our folder.
  45. // Otherwise, we are building TApplication and within that folder.
  46.  
  47. #include "TDocument.h"
  48.  
  49. /*
  50.     TApplication:
  51.  
  52.     This is our class which implements a basic Macintosh style program,
  53.     including a MultiFinder-aware event loop. 
  54. */
  55.  
  56. class TApplication 
  57. {
  58.     public:
  59.         //    these member functions can be called by anyone
  60.                     TApplication            ( void );                                // Our constructor & destructor
  61.             void    EventLoop                ( void );                                // Call this routine to start event loop running
  62.             inline    TDocumentList* DocList    ( void )        { return fDocList; }    // a utility routine that you may need to use
  63.             Boolean TrapAvailable            ( short theTrap );                        // Is trap implemented???
  64.     
  65.     protected:
  66.         // useful variables
  67.             Boolean            fHaveWaitNextEvent;        // true if we have WaitNextEvent trap
  68.             Boolean            fDone;                    // set to true when we are ready to quit
  69.             EventRecord        fTheEvent;                // our event record
  70.             WindowPtr        fWhichWindow;            // currently active window
  71.             Boolean            fInBackground;            // true if our app is suspended
  72.             Boolean            fWantFrontClicks;        // true if we want front clicks
  73.             RgnHandle        fMouseRgn;                // mouse moved region (set it in your DoIdle)
  74.             TDocument*        fCurDoc;                // currently active document (if any)
  75.             TDocumentList*    fDocList;                // the list of documents
  76.  
  77.         // Returns total stack space required in bytes.
  78.         // Returns 0 by default, which tells the initialization code
  79.         // to use the default stack size.
  80.             virtual long StackNeeded        ( void )     { return 0; }
  81.     
  82.         // Returns total heap space required in bytes.
  83.         // Returns 0 by default, which tells the initialization code
  84.         // to use whatever heap size is given.
  85.             virtual long HeapNeeded            ( void )    { return 0; }
  86.     
  87.         // Loop control methods you may need to override
  88.             virtual void AdjustMenus        ( void )    {}                // menu updater routine
  89.             virtual void CleanUp            ( void )    {}                // run at end of loop
  90.             virtual void DoIdle                ( void )    {}                // idle time handler (blink caret, background tasks)
  91.             virtual void ExitLoop            ( void );                    // to end loop, call this routine
  92.             virtual void SetUp                ( void )    {}                // Run before event loop starts
  93.     
  94.         // event handlers you shouldn't need to override in a typical application
  95.             virtual void DoMouseInSysWindow    ( void )     { SystemClick(&fTheEvent, fWhichWindow); }
  96.             virtual void DoOSEvent            ( void );                    // Calls DoSuspend, DoResume and DoIdle as apropos
  97.             virtual void DoMouseDown        ( void );                    // Calls DoContent, DoGrow, DoZoom, etc
  98.             virtual void DoKeyDown            ( void );                    // also called for autokey events
  99.             virtual void DoActivateEvt        ( void );                    // handles setup, and calls DoActivate ( below)
  100.             virtual void DoGoAway            ( void );                    // handles setup, calls TDocument::DoClose
  101.             virtual void DoUpdateEvt        ( void );                    // handles setup, and calls DoUpdate ( below )
  102.             virtual void DoDrag                ( void );
  103.     
  104.         // handlers you will need to override for functionality:
  105.             // called by EventLoop and its handlers:
  106.                 virtual void AdjustCursor    ( void )    {}                // cursor adjust routine, should setup mouseRgn
  107.                 virtual void DoMenuCommand    ( short menuID, short menuItem )    { (void) menuID; (void) menuItem; /* avoid "not used" warning */}
  108.     
  109.             // called by OSEvent (just calls DoActivate by default, so no clip conversion
  110.             // is done). If you want to convert clipboard, override these routines
  111.                 virtual void DoSuspend(Boolean doClipConvert);
  112.                 virtual void DoResume(Boolean doClipConvert);
  113.         
  114.         // If you have an app that needs to know about these, override them
  115.             virtual void DoMouseUp( void ) {}
  116.             virtual void DoDiskEvt( void ) {}
  117.     
  118.         // Utility routines you need to provide to do MultiFinder stuff
  119.             virtual unsigned long SleepVal( void ) { return 0; }        // how long to sleep in WaitNextEvent
  120.  
  121.         // some other handy utility routines
  122.             // display alert, using specified error STR# resource and error code as index
  123.                 void AlertUser( short errResID, short errCode );
  124.             
  125.             // call AlertUser to display error message, then quit...
  126.                 void BigBadError( short errResID, short errCode );
  127.  
  128. }; /* class TApplication */
  129.  
  130. #endif
  131.